package com.mszlu.news.controller;

import com.mszlu.news.service.SysUserService;
import com.mszlu.news.vo.Result;
import com.mszlu.news.vo.params.PageParams;
import com.mszlu.news.vo.params.SysUserParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户接口")
@RestController
@RequestMapping("users")
public class UsersController {

    @Autowired
    private SysUserService sysUserService;

    @ApiOperation(value = "获取所有用户信息")
    @PostMapping("alluser")
    public Result allUser(@RequestBody PageParams params){
        return sysUserService.findAllUser(params);
    }

    ///users/currentUser
    @ApiOperation(value = "通过token获取当前用户信息")
    @GetMapping("currentUser")
    public Result currentUser(@RequestHeader("Authorization") String token){
        return sysUserService.findUserByToken(token);
    }

    @ApiOperation(value = "根据用户id查找用户个人信息")
    @PostMapping("userInfo/{id}")//根据用户id查找用户个人信息
    public Result userInfo(@PathVariable("id") Long id){
        return sysUserService.findUserInfoById(id);
    }

    @ApiOperation(value = "修改用户信息")
    @PostMapping("update")
    public Result updateUser(@RequestBody SysUserParam sysUserParam){
        return sysUserService.updateUser(sysUserParam);
    }

    @ApiOperation(value = "搜索用户")
    @PostMapping("select")
    public Result selectUser(@RequestBody SysUserParam sysUserParam){
        return sysUserService.selectUser(sysUserParam);
    }
}
